1 Imports System.Data.SqlClient
2 Public Class Ban_ve
3     Private bang_tuyen_xe As DataTable
4     Private bang_Thoi_diem_ngay As DataTable
5     Private bang_Thoi_diem_gio As DataTable
6     Private bang_Xe As DataTable
7     Private bang_Thong_tin_xe As DataTable
8
9     Private bang_dat_ve As DataTable
10     Public IdChuyen As String
11     Public So_cho_ngoi As String
12
13     Private lenh As String
14  
15     Public Sub Update_Ve_xe()
16         Doc_tuyen_xe()
17         doc_bang_ve()
18         Clear_Controls()
19     End Sub
20
21     Private Sub doc_bang_ve()
22         lenh =
"Select IdVe, TenHanhKhach, SDTHanhKhach, TenTuyen, NgayDi, Gio, So_Xe from BanVe, ChuyenXe, TuyenXe "
23         lenh &=
" where BanVe.IdChuyen = ChuyenXe.IdChuyen and ChuyenXe.IdTuyen = TuyenXe.IdTuyen"
24         bang_dat_ve = Doc_bang(lenh)
25         With Form_Main.cbo_MaSoVe
26             .DataSource = bang_dat_ve
27             .ValueMember =
"IdVe"
28             .DisplayMember =
"IdVe"
29         End With
30
31         
'Tao lien ket
32         Form_Main.luoi_ThongTinDatVe.DataSource = bang_dat_ve
33
34     End Sub
35
36
37
38
39     Private Sub Clear_Controls()
40         With Form_Main
41             .cbo_TenTuyenVe.Text =
""
42             .cbo_NgayVe.Text =
""
43             .cbo_GioVe.Text =
""
44             .cbo_XeVe.Text =
""
45         End With
46     End Sub
47
48     Private Sub Doc_tuyen_xe()
49         lenh =
"Select Distinct ChuyenXe.IdTuyen, TenTuyen from ChuyenXe, TuyenXe where TuyenXe.IdTuyen = ChuyenXe.IdTuyen"
50         bang_tuyen_xe = Doc_bang(lenh)
51         With Form_Main.cbo_TenTuyenVe
52             .DataSource = bang_tuyen_xe
53             .DisplayMember =
"TenTuyen"
54             .ValueMember =
"IdTuyen"
55         End With
56     End Sub
57
58     Public Sub Chon_tuyen()
59         If Form_Main.cbo_TenTuyenVe.SelectedIndex <
0 Then Exit Sub
60         Loc_ngay_theo_tuyen(Form_Main.cbo_TenTuyenVe.SelectedValue.ToString)
61     End Sub
62
63     Private Sub Loc_ngay_theo_tuyen(ByVal IdTuyen As String)
64         lenh =
"Select Distinct NgayDi from ChuyenXe where IdTuyen = '" + IdTuyen + "'"
65         bang_Thoi_diem_ngay = Doc_bang(lenh)
66         With Form_Main.cbo_NgayVe
67             .DataSource = bang_Thoi_diem_ngay
68             .ValueMember =
"NgayDi"
69             .DisplayMember =
"NgayDi"
70         End With
71     End Sub
72
73     Public Sub Chon_ngay()
74         If Form_Main.cbo_GioVe.Text =
"" And Form_Main.cbo_XeVe.Text = "" Then
75             Form_Main.cbo_NgayVe.Text =
""
76         End If
77         If Form_Main.cbo_NgayVe.SelectedIndex <
0 Then Exit Sub
78         Loc_gio_theo_ngay(Form_Main.cbo_NgayVe.SelectedValue.ToString)
79     End Sub
80
81     Private Sub Loc_gio_theo_ngay(ByVal Ngay As String)
82         lenh =
"Select Gio from ChuyenXe where NgayDi = '" + Ngay + "' and IdTuyen = '" + Form_Main.cbo_TenTuyenVe.SelectedValue.ToString + "'"
83         bang_Thoi_diem_gio = Doc_bang(lenh)
84         With Form_Main.cbo_GioVe
85             .DataSource = bang_Thoi_diem_gio
86             .ValueMember =
"Gio"
87             .DisplayMember =
"Gio"
88         End With
89     End Sub
90
91     Public Sub Chon_xe()
92         If Form_Main.cbo_XeVe.Text =
"" Then
93             Form_Main.cbo_GioVe.Text =
""
94         End If
95         If Form_Main.cbo_GioVe.SelectedIndex <
0 Then Exit Sub
96         Loc_xe_theo_gio(Form_Main.cbo_GioVe.SelectedValue.ToString)
97     End Sub
98
99     Private Sub Loc_xe_theo_gio(ByVal Gio As String)
100         lenh =
"Select So_Xe from ChuyenXe where Gio = '" + Gio + "' and IdTuyen = '" + Form_Main.cbo_TenTuyenVe.SelectedValue.ToString + "' and NgayDi = '" + Form_Main.cbo_NgayVe.SelectedValue.ToString + "'"
101         bang_Xe = Doc_bang(lenh)
102         With Form_Main.cbo_XeVe
103             .DataSource = bang_Xe
104             .ValueMember =
"So_Xe"
105             .DisplayMember =
"So_Xe"
106         End With
107     End Sub
108
109     Public Sub Chon_thong_tin_xe()
110         If Form_Main.cbo_GioVe.Text =
"" Then
111             Form_Main.cbo_XeVe.Text =
""
112         End If
113         If Form_Main.cbo_TenTuyenVe.Text <>
"" And Form_Main.cbo_XeVe.Text <> "" And Form_Main.cbo_GioVe.Text <> "" And Form_Main.cbo_NgayVe.Text <> "" Then
114             If Form_Main.cbo_XeVe.SelectedIndex <
0 Then Exit Sub
115             Loc_thong_tin_theo_so_xe(Form_Main.cbo_XeVe.SelectedValue.ToString)
116
117         End If
118     End Sub
119
120     Private Sub Loc_thong_tin_theo_so_xe(ByVal So_Xe As String)
121         lenh =
"Select * From Xe where So_Xe = '" + So_Xe + "'"
122         bang_Thong_tin_xe = Doc_bang(lenh)
123         Form_Main.luoi_XeVe.DataSource = bang_Thong_tin_xe
124     End Sub
125
126     
'Xu ly nut chon cho ngoi
127     Public Sub Chon_cho_ngoi()
128         With Form_Main
129             If Kiem_tra_thong_tin_dat_ve() Then
130                 lenh =
"Select So_Cho_Ngoi From Xe where So_Xe = '" + .cbo_XeVe.SelectedValue.ToString + "'"
131                 bang_Thong_tin_xe = Doc_bang(lenh)
132                 So_cho_ngoi = bang_Thong_tin_xe.Rows(
0)("So_Cho_Ngoi").ToString
133
134                 If CInt(So_cho_ngoi) =
7 Then
135                     Dim frm_xe_7 As New Form_Xe_7_Cho()
136                     frm_xe_7.Show()
137                 End If
138
139                 If CInt(So_cho_ngoi) =
16 Then
140                     Dim frm_xe_16 As New Form_Xe_16_Cho()
141                     frm_xe_16.Show()
142                 End If
143
144                 If CInt(So_cho_ngoi) =
25 Then
145                     Dim frm_xe_25 As New Form_Xe_25_Cho()
146                     frm_xe_25.Show()
147                 End If
148
149                 If CInt(So_cho_ngoi) =
30 Then
150                     Dim frm_xe_30 As New Form_Xe_30_Cho()
151                     frm_xe_30.Show()
152                 End If
153
154                 If CInt(So_cho_ngoi) =
45 Then
155                     Dim frm_xe_45 As New Form_Xe_45_Cho()
156                     frm_xe_45.Show()
157                 End If
158
159             End If
160         End With
161
162     End Sub
163
164     Private Function Kiem_tra_thong_tin_dat_ve() As Boolean
165         Kiem_tra_thong_tin_dat_ve = True
166         With Form_Main
167             If .cbo_TenTuyenVe.Text =
"" OrElse .cbo_NgayVe.Text = "" OrElse .cbo_GioVe.Text = "" OrElse .cbo_XeVe.Text = "" _
168              OrElse .txt_TenHanhKhach.Text =
"" OrElse .txt_SoDTHanhKhach.Text = "" Then
169                 Kiem_tra_thong_tin_dat_ve = False
170                 MessageBox.Show(
"Phải nhập đầy đủ thông tin đặt vé!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand)
171                 Exit Function
172             End If
173
174             If .txt_SoDTHanhKhach.Text.Length >
12 OrElse .txt_SoDTHanhKhach.Text.Length < 9 Then
175                 Kiem_tra_thong_tin_dat_ve = False
176                 MessageBox.Show(
"So điện thoại từ 9 đến 12 ký tự", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand)
177                 Exit Function
178             End If
179         End With
180     End Function
181 End Class



Quản lý phần mềm bán vé xe VB 8.405 lượt xem

Gõ tìm kiếm nhanh...